package com.lanyam.travel.base.service.impl;


import com.lanyam.travel.base.entity.DistrSetting;
import com.lanyam.travel.base.entity.vo.DistrSettingVo;
import com.lanyam.travel.base.dao.DistrSettingMapper;
import com.lanyam.travel.base.service.IDistrSettingService;
import org.springframework.beans.BeanUtils;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;


@Service
@Transactional
@Slf4j
public class DistrSettingServiceImpl implements IDistrSettingService {

    @Resource
    private DistrSettingMapper distrSettingMapper;

    @Override
    public IPage<DistrSettingVo> getPageDistrSetting (Map<String, Object> queryMap, Integer page, Integer rows) {
        Page<DistrSettingVo> pageSize = new Page<DistrSettingVo>(page, rows);
        Page<DistrSettingVo> pageInfo = distrSettingMapper.getPage(pageSize, queryMap);
        return pageInfo;
    }

    @Override
    public void addDistrSetting(DistrSetting distrSetting) {
        distrSettingMapper.insert(distrSetting);
    }

    @Override
    public void updateDistrSetting(DistrSetting distrSetting) {
        int count = distrSettingMapper.getCount();
        if (count > 0) {
            distrSettingMapper.updateSettingData(distrSetting);
        } else {
            distrSettingMapper.insert(distrSetting);
        }
//        distrSettingMapper.updateById(distrSetting);
    }

    @Override
    public void delById(String id) {
        distrSettingMapper.delById(id);
    }

    @Override
    public DistrSettingVo getDistrSetting() {
        List<DistrSetting> settings = distrSettingMapper.selectList(null);
        DistrSetting setting = settings.get(0);
        DistrSettingVo settingVo = new DistrSettingVo();
        BeanUtils.copyProperties(setting,settingVo);
        return settingVo;
    }

    @Override
    public DistrSetting getSettingData() {
        DistrSetting settingData = distrSettingMapper.getSettingData();
        return settingData;
    }
}